<template>
	
	<view class="crm">
		<!-- <u-sticky> -->
		<view class="tops1">
			<view class="searchBox">
				<view class="search">
					<view class="inp">
						<u-search @change="changeInpFn"  :clearabled="true" @clear="search" @search="search" bg-color="#fff" :show-action="false" height="60" search-icon=""
							placeholder-color="rgba(15, 20, 23, 0.3)" placeholder="请输入手机号或ID号" v-model="keyword">
						</u-search>
					</view>
					<view class="btns" @click="search">
						搜索
					</view>
				</view>

			</view>
			<view class="selectOptions">
				<view class="left">
					<piaoyi-select @sendDate="sendDate" :inputValue.sync="inputValue"
						ref="piaoyiSelect" :clearable="clearable" :filterable="filterable" :placeholder="placeholder"
						:options="options"></piaoyi-select>

				</view>
				<view class="right">
团队数量：<text>{{entityCount}}</text>
				</view>
			</view>

		</view>
		<!-- </u-sticky> -->
		<view v-if="list1.length" class="list" :style="{'padding-top': paddingTop}">
			<view class="item" v-for="(item,index) in list1" @click="godetail(item)">
				<view class="tops">
					<view class="left">
						<view class="leftBox">
							<view class="photo">
								<image :src="item.avatar?item.avatar:'https://oss.6mate.cn/mini/boy1.png'" mode=""></image>
								<!-- <view class="sex">
									<image v-if="item.gender=='FEMALE'" src="
https://oss.6mate.cn/mini/girl.png"
										mode=""></image>
									<image v-else src="
https://oss.6mate.cn/mini/boy.png" mode="">
									</image>
		
								</view> -->
							</view>
		
							<view class="names">
								<view class="name">
									<view class="fullname">{{item.realName}}</view>
									<view class="tags"  :class="[GetcardTypeCodeColor(item)]"> {{item.statusName}}
									<!-- 基础VIP -->
									</view>
								</view>
								<view class="code">
									
									{{item.info}}
									<!-- ID：11752268 <view class="line">
									</view> 手机号：15847665823 -->
									
								</view>
							</view>
						</view>
						
					</view>
		
				</view>
		
			</view>
			<uni-load-more :status="status"></uni-load-more>
		</view>
		<view v-else class="empty" style="padding-top: 150px;">
			<view v-if="!list1.length && senDate" class="emptyAddress-box">
				<u-empty text="暂无内容" mode="news"></u-empty>
			</view>
		</view>


	</view>
</template>

<script>
	import piaoyiSelect from '@/uni_modules/piaoyi-select/components/piaoyi-select/piaoyi-select.vue'
	
	export default {
		components: {
			piaoyiSelect
		},
		data() {
			return {
				clearable: false,
				filterable: false,
				inputValue: '',
				
				// 状态：ENABLE正常，EXPIRE已过期，DISABLE已停用
				options: [{
					label: '全部',
					value: '全部',
					key:''
				}, {
					label: '正常',
					value: '正常',
					key:'ENABLE'
				}, {
					label: '已过期',
					value: '已过期',
					key:'EXPIRE'
				}, {
					label: '已停用',
					value: '已停用',
					key:'DISABLE'
				}],
				placeholder: '筛选',

				barStyle: {
					'width': '96rpx',
					'height': '4rpx',
					'background': 'linear-gradient( 211deg, #EF8548 0%, #DE4543 100%)'
				},
				claName: '',
				checkAll: false,
				curId: '',
				curPhone: '',
				transferPhone: '',
				transferToAppMask: false,
				total: null, //总共多少条数据
				formData: {
					pageSize: 10, //每页10条数据
					page: 1, //第几页
					status: "",
				},
				
				status: "more",
				senDate: false,
				list1: [],

				keyword: '',
				gender: "",
				isVip: "",
				cardTypeIds: [],
				paddingTop: "",
				entityCount:''

			}
		},
		onReady() {
			uni.createSelectorQuery().select('.tops1').boundingClientRect((rect) => {
				console.log(rect.height, 66666);
				this.paddingTop = rect.height + 'px'
			}).exec()
		},
		onLoad() {

			this.getlist()

		},
		onPullDownRefresh() {
			
			// uni.showLoading({
			// 	title: '刷新中...',
			// 	mask: true
			// })
			this.formData.page = 1;
			// this.list1 = [];
			this.getlist('fresh');
		},
		onReachBottom() {
			let allTotal = this.formData.page * this.formData.pageSize;
			if (allTotal < this.total) {
				//当前条数小于总条数 则增加请求页数
				this.status = "loading"; //加载中状态
				this.formData.page++;
				this.getlist();
			} else {
				this.status = "noMore"; //加载完状态
				console.log("已加载全部数据");
			}
		},
		methods: {
			changeInpFn(e){
				
				if(e==''){
					this.formData.page = 1;
					this.getlist('fresh');
				}
				
			},
			
			// 状态：ENABLE正常，EXPIRE已过期，DISABLE已停用
			GetcardTypeCodeColor(item){
				 if(item.status=='ENABLE'){
					return 'base'
				}else if(item.status=='EXPIRE'){
					return 'ending'
				}else {
					return 'over'
				}
			},
			sendDate(val) {
				console.log(val.key, 555555555555)
				
				this.formData.status =val.key
				// this.inputValue = val.label
				// this.formData.page = 1
				// this.list1 = []
				// this.getlist()
				
				this.formData.page = 1;
				this.getlist('fresh');
			},
			search() {
				// this.formData.page = 1
				// this.list1 = []
				// this.getlist()
				this.formData.page = 1;
				this.getlist('fresh');
			},
			getlist(type) {
				this.senDate = false;
				let query = {
					pageIndex: this.formData.page,
					pageSize: this.formData.pageSize,
					status: this.formData.status,
					keyWord: this.keyword
				}

				this.$u.api
					.miniUserPage(query)
					.then((res) => {
						if(type=='fresh'){
							this.list1 = [];
						}
						this.senDate = true;
						if (res.code == 'ok') {
							this.entityCount = res?.data?.entityCount
							this.total = res.data.entityCount;
							const newlist = res.data.entities;
							this.list1.push(...newlist);
							if (this.list1.length < this.formData.pageSize) {
								this.status = "noMore"; //加载完状态
							}
						} else {}
						uni.stopPullDownRefresh()
						uni.hideLoading();
					});
			},

			godetail(e) {

				uni.navigateTo({
					url: "/teamPack/myTeam/detail?id=" + e.id
				})
			}
		}
	}
</script>

<style>
	page {
		background: #fff;
	}
</style>
<style scoped lang="scss">
	.crm {
		padding: 0 0 24rpx;

		.tops1 {
			background: #FFFFFF;
			padding: 24rpx 0 0;
			position: fixed;
			left: 0;
			top: 0;
			right: 0;
			z-index: 9;
		}
		.selectOptions{
			padding: 20rpx 40rpx 0;
			display: flex;
			align-items: center;
			justify-content: space-between;
			.right{
				font-family: Alibaba PuHuiTi, Alibaba PuHuiTi;
				font-weight: 400;
				font-size: 24rpx;
				color: rgba(15,20,23,0.6);
				line-height: 28rpx;
				text{
					color: #0F1417;
				}
			}
		}

		.list {
			margin-top: -24rpx;
			padding: 0 32rpx;
		
			.item {
				padding: 30rpx 0;
				border-bottom: 1rpx solid #F6F6F6;
		
				.tops {
					display: flex;
					align-items: center;
					justify-content: space-between;
		
					.btns {
						display: flex;
						align-items: center;
		
						>view {
							display: flex;
							align-items: center;
							justify-content: center;
						}
		
						.xufei {
							width: 120rpx;
							height: 64rpx;
							border-radius: 40rpx 40rpx 40rpx 40rpx;
							border: 2rpx solid #D9D9D9;
							font-family: Alibaba PuHuiTi, Alibaba PuHuiTi;
							font-weight: 400;
							font-size: 28rpx;
							color: #0F1417;
							line-height: 40rpx;
							margin-right: 16rpx;
						}
		
						.shengji {
							font-family: Alibaba PuHuiTi, Alibaba PuHuiTi;
							font-weight: 400;
							font-size: 28rpx;
							color: #FA4A53;
							line-height: 40rpx;
							width: 120rpx;
							height: 64rpx;
							background: #FFFFFF;
							border-radius: 72rpx 72rpx 72rpx 72rpx;
							border: 2rpx solid #FA4A53;
						}
		
						.kaitong {
							font-family: Alibaba PuHuiTi, Alibaba PuHuiTi;
							font-weight: 400;
							font-size: 28rpx;
							color: #FFFFFF;
							line-height: 40rpx;
							width: 120rpx;
							height: 64rpx;
							background: #FA4A53;
							border-radius: 72rpx 72rpx 72rpx 72rpx;
							border: 2rpx solid #FA4A53;
						}
					}
		
		
					.left {
						flex: 1;
						display: flex;
						justify-content: space-between;
		
						.leftBox {
							display: flex;
							align-items: center;
						}
		
						.photo {
							margin-right: 20rpx;
							position: relative;
							width: 120rpx;
							height: 120rpx;
							border-radius: 50%;
							// border: 1rpx solid #bc2ef3;
							// overflow: hidden;
							image {
								display: block;
								width: 120rpx;
								height: 120rpx;
								border-radius: 50%;
							}
		
							.sex {
								position: absolute;
								width: 32rpx;
								height: 32rpx;
								// background: #FA4A53;
								border-radius: 50%;
								border: 2rpx solid #F7F8FA;
								bottom: 0;
								right: 0;
		
								image {
									display: block;
									width: 28rpx;
									height: 28rpx;
								}
							}
						}
		
						.names {
							flex: 1;
		
							.name {
								display: flex;
								align-items: center;
								// justify-content: space-between;
								padding-top: 18rpx;
		
								.fullname {
									font-family: Alibaba PuHuiTi, Alibaba PuHuiTi;
									font-weight: 500;
									font-size: 28rpx;
									color: #0F1417;
									line-height: 33rpx;
								}
		
								
		
		
							}
		
							.code {
								margin-top: 16rpx;
								// color: rgba(15, 20, 23, 0.6);
								display: flex;
								align-items: center;
								// line-height: 1;
								font-family: Alibaba PuHuiTi, Alibaba PuHuiTi;
								font-weight: 400;
								font-size: 24rpx;
								color: rgba(15,20,23,0.7);
								// line-height: 28rpx;
		
							.line{
								width: 2rpx;
								height: 22rpx;
								background: #BDB7B7;
								margin: 2rpx 10rpx 0;
							}
		
							}
						}
					}
		
				}
			}
		}
		.tags {
			font-family: Alibaba PuHuiTi, Alibaba PuHuiTi;
			font-weight: 400;
			font-size: 20rpx;
			margin-left: 8rpx;
			line-height: 20rpx;
			padding: 4rpx 10rpx;
			border-radius: 14rpx 14rpx 14rpx 14rpx;
			color:#fff;
				
			&.base {
				color: #FFFFFF !important;
				background: #1BAB6B !important;
			}
				
			&.over {
				// color: #FFE1CF !important;
				background:#6F7274 !important;
			}
				
			&.ending {
				color: #FFE1CF !important;
				background: #FA4A53 !important;
			}
				
			
		}
		
		
		.borderGap {
			// margin-bottom: 8rpx;
			border-bottom: 2rpx solid #E7E7E7;
			margin-top: -4rpx;

		}

		.searchBox {
			display: flex;
			align-items: center;
			justify-content: space-between;
			margin: 0 32rpx 0;
		}

		.search {
			flex: 1;

			height: 64rpx;
			background: #FFFFFF;
			border-radius: 152rpx 152rpx 152rpx 152rpx;
			border: 2rpx solid #FA4A53;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.inp {
				flex: 1;
			}

			.btns {
				display: flex;
				align-items: center;
				justify-content: center;
				font-family: Alibaba PuHuiTi, Alibaba PuHuiTi;
				font-weight: 400;
				font-size: 24rpx;
				color: #FFFFFF;
				line-height: 40rpx;
				margin: 4rpx;
				width: 128rpx;
				height: 56rpx;
				background: #FA4A53;
				border-radius: 152rpx 152rpx 152rpx 152rpx;
			}
		}

	}
</style>
